#include<bits/stdc++.h>
#define int long long
using namespace std;
namespace IO
{
	template<typename T>
	void read(T &_x){_x=0;int _f=1;char ch=getchar();while(!isdigit(ch)) _f=(ch=='-'?-1:_f),ch=getchar();while(isdigit(ch)) _x=_x*10+(ch^48),ch=getchar();_x*=_f;}
	template<typename T,typename... Args>
	void read(T &_x,Args&...others){Read(_x);Read(others...);}
	const int BUF=20000000;char buf[BUF],top,stk[32];int plen;
	#define pc(x) buf[plen++]=x
	#define flush(); fwrite(buf,1,plen,stdout),plen=0;
	template<typename T>inline void print(T x){if(!x){pc(48);return;}if(x<0) x=-x,pc('-');for(;x;x/=10) stk[++top]=48+x%10;while(top) pc(stk[top--]);}
}
using namespace IO;
const int N = 5e4+10;
int n,m,fa[N][20],dep[N],lg[N],a[N],v[N],l,r,ans;
vector<int>w[N];
void dfs(int x,int y)
{
	dep[x] = dep[y]+1;
	for(int j = 1;j <= lg[dep[x]];j++)
		fa[x][j] = fa[fa[x][j-1]][j-1];
	for(int i = 0;i < w[x].size();i++) 
		dfs(w[x][i],x);
}
int lca(int x,int y)
{
	if(dep[x] < dep[y]) swap(x,y);
	while(dep[x] != dep[y]) x = fa[x][lg[dep[x]-dep[y]]];
	if(x == y) return x;
	for(int i = lg[dep[x]];i >= 0;i--)
		if(fa[x][i] != fa[y][i]) x = fa[x][i],y = fa[y][i];
	return fa[x][0];
}
signed main()
{
	freopen("escape.in","r",stdin);
	freopen("escape.out","w",stdout);
	read(n),read(m); dep[0] = -1;
	for(int i = 2;i <= n;i++) read(fa[i][0]),w[fa[i][0]].push_back(i),v[fa[i][0]]++,lg[i] = lg[i/2]+1;
	dfs(1,0);
	for(int i = 1;i <= n;i++) read(a[i]);
	for(int i = 1;i <= n;i++) if(v[i] > 1) l = 1;
	if(l == 0)
	{
		while(m--)
		{
			read(l),read(r);
			print(r-l+1),pc('\n');
		}
		flush();
		return 0;
	}
	while(m--)
	{
		read(l),read(r); ans = 0;
		for(int i = 1;i <= n;i++) v[i] = 0;
		for(int i = l;i <= r;i++)
			for(int j = l;j <= r;j++)
				if(!v[lca(a[i],a[j])]) v[lca(a[i],a[j])] = 1,ans++;
		print(ans),pc('\n');
	}
	flush();
	return 0;
}



